<!--
 * @Author: CNN 969682281@qq.com
 * @Date: 2023-03-07 13:36:39
 * @LastEditors: 贺楠 1071780426@qq.com
 * @LastEditTime: 2024-08-08 10:52:31
 * @FilePath: \newMould_BHZ\src\views\WaterManage\trends\instantly.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <!-- 水稳----动态监控---实时监控 -->
  <div class="department" id="department">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
        <div>
          <!-- <el-checkbox v-model="checked" @change="see()">查看下级</el-checkbox> -->
        </div>
      </div>
      <tree
        :treeData="treeData"
        :checkData="checkData"
        nodeKey="fCompanyid"
        @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps"
      >
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->

        <div class="mechanism_nav_left" style="width: 100%">
          <el-date-picker
            class="selectBhz"
            @change="selectTime"
            v-model="getList.timeStr"
            type="year"
            placeholder="选择年"
            format="yyyy 年"
            value-format="yyyy"
          >
          </el-date-picker>
          <el-select
            class="selectBhz"
            v-model="getList.stationId"
            placeholder="梁场查询"
            @change="selectBhz"
            style="width: 160px"
          >
            <el-option
              v-for="v in bhzDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>
          <el-select
            class="selectBhz"
            v-model="getList.machineId"
            placeholder="压浆机查询"
            @change="yj_searchForm(getList)"
            style="width: 160px"
          >
            <el-option
              v-for="v in bhjDataList"
              :key="v.fItemName"
              :label="v.fItemName"
              :value="v.fItemValue"
            >
            </el-option>
          </el-select>
        </div>
        <!-- 顶部按钮 -->
        <div class="print"></div>
      </div>

      <!-- 内容 -->
      <div class="text_table">
        <div class="materialTable" style="height: 200px">
          <tableData
            v-if="table_config.thead.length > 1"
            :config="table_config"
            :dataList="tableData"
            :loading="listLoading"
            @selection-change="selectionChange"
            @sort-change="sortChange"
          />
        </div>

        <div class="materialCharts">
          <myCharts
            :time1="this.value2[0]"
            :time2="this.value2[1]"
            :commonData="chartsData"
          >
          </myCharts>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import vDatePicker from "@/components/public/v-DatePicker";
import tree from "@/components/stationProductionPage/GroutManage/tree"; //左侧机构树
import TableData from "@/components/public/el-table"; //主页面列表
import elBreadcrumb from "@/components/public/el-breadcrumb.vue"; //面包屑
import myCharts from "@/components/stationProductionPage/GroutManage/GroutExceedHandlecharts";

// import formJs from "./regexDetail.js"; //新增弹框配置项
import {
  getUserCompanyTreeList, //左侧机构树接口
  getGroutingTrend, //主页面列表接口
  getStationmachineList, //梁场设备查询
  getMachineListByStationId, //4张拉机、5压浆机设备查询
} from "@/api/request.js";
// import { statusTypes } from "@/utils/config"; //配置项
export default {
  name: "TensionExceedHandle",
  components: {
    tree, //左侧组织机构数
    TableData, //主页面列表
    elBreadcrumb, //面包屑
    myCharts,
    // vDatePicker,
  },
  data() {
    return {
      name: "TensionExceedHandle", //按钮配置页面代号
      // 顶部下拉框
      bhzDataList: [], //梁场
      bhjDataList: [], //张拉机
      value2: "", //主页面日期筛选绑定值
      value1: "",

      // 顶部下拉框

      // 列表
      table_config: {
        imgKeyWord: "url",
        fileKeyWord: "url",
        fileName: "fFileName",
        dialogHeight: "",
        thead: [],
        isCheckBox: false,
        isIndex: false,
        isOperation: true,
        // 表格操作列
      },

      tableData: [], //列表数据列表
      listLoading: false, //列表数据加载loading
      getList: {
        fprojectid: "",
        fCompanyid: "", // 施工标段id，不为空
        startDates: "", // 开始时间
        endDates: "", // 截至时间
        stationId: "", // 梁场id
        machineId: "", // 压浆机id
        warningLevel: "", // 预警等级
        fCloseoperation: "", // 闭合状态
        keyWord: "", //  模糊条件
        page: 1, // 当前页数
        pageSize: 20, // 每页显示条数
        timeStr: "", // 趋势---查询的年份
        fProjectposition: "", //任务单--工程部位模糊查询
        taskNo: "", //任务单---任务单模糊查询
        fStatus: "", //任务单--完成状态
        keyType: "2", //张拉 1 压浆 2 必填
        modelType: "2",
        fNote: "0", //新加参数 瑞仓1   其他0

      },
      //echarts
      chartsData: {}, //echarts数据
      //echarts

      // 左侧机构树
      companyTree: "", //所有数据
      checked: true, //查看下级按钮
      treelength: false, //左侧树显示隐藏
      showName: "未选择公司",
      treeData: [], //左侧树状图数据
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      checkData: [],
      treeText: {
        //树状图参数
        companyId: null,
        text: null,
        userId: null,
      },
      // 左侧机构树
      userInfo: {}, //登录用户
    };
  },

  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));

    if (JSON.parse(sessionStorage.getItem("yjSmart-GroutManage_getLists"))) {
      var dataList = JSON.parse(
        sessionStorage.getItem("yjSmart-GroutManage_getLists")
      );
      this.getList = {
        fprojectid: dataList.fCompanyid, //任务单
        fCompanyid: dataList.fCompanyid, // 施工标段id，不为空
        startDates: dataList.startDates, // 开始时间
        endDates: dataList.endDates, // 截至时间
        stationId: dataList.stationId, // 梁场id
        machineId: dataList.machineId, // 压浆机id
        warningLevel: dataList.warningLevel, // 超标查询
        fCloseoperation: dataList.fCloseoperation, // 闭合状态
        keyWord: dataList.keyWord, //  模糊条件
        page: 1, // 当前页数
        pageSize: 20, // 每页显示条数
        timeStr: dataList.timeStr, // 趋势---查询的年份
        fProjectposition: dataList.fProjectposition, //任务单--工程部位模糊查询
        taskNo: dataList.taskNo, //任务单---任务单模糊查询
        fStatus: dataList.fStatus, //任务单--完成状态
        keyType: "2", //张拉 1 压浆 2 必填
        modelType: "2",
        fNote: "0", //新加参数 瑞仓1   其他0

      };
    }

    if (JSON.parse(sessionStorage.getItem("yjSmart-GroutManage_treeCheck"))) {
      var id = JSON.parse(
        sessionStorage.getItem("yjSmart-GroutManage_treeCheck")
      );
      this.checkData = [id.fCompanyid];
    }

    this.getTree();
    this.getDate();
    // this.btnRole(this.name);
  },
  methods: {
    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-instantly"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        // this.yj_view = btnStr.includes("yj_view");
      } else {
        // this.yj_view = true;
      }
    },
    // 左侧树结构
    getTree() {
      this.treeText = {
        companyId: this.userInfo.companyId,
        userId: this.userInfo.userId,
        text: "4", // 0其他  1 砼拌合站 2水稳 3沥青
      };
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);
            if (this.treeData[0].children == undefined) {
              this.treelength = false; //左侧组织机构是否显示
            } else {
              this.treelength = true;
            }

            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("yjSmart-GroutManage_treeCheck")
              ).fShortname;

              this.getList.fCompanyid = this.checkData[0];
            } else {
              this.checkData[0] = this.treeData[0].fCompanyid;
              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.getList.fCompanyid = this.treeData[0].fCompanyid; //当前点击组织机构ID
            }
            this.mixingPlantList(0, this.getList);
            this.yj_searchForm(this.getList); // 调用主页面列表接口
            // 列表
          } else {
            this.$message.error(res.msg);
            // this.$message.error("获取组织机构失败");
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },
    // 点击左侧机构树
    handleNodeClick(data) {
      this.showName = data.fShortname; //顶部显示机构名

      if (JSON.parse(sessionStorage.getItem("yjSmart-GroutManage_getLists"))) {
        var dataList = JSON.parse(
          sessionStorage.getItem("yjSmart-GroutManage_getLists")
        );
        this.getList = {
          fprojectid: dataList.fCompanyid, //任务单
          fCompanyid: data.fCompanyid, // 施工标段id，不为空
          startDates: dataList.startDates, // 开始时间
          endDates: dataList.endDates, // 截至时间
          stationId: "", // 梁场id
          machineId: "", // 压浆机id
          warningLevel: dataList.warningLevel, // 超标查询
          fCloseoperation: dataList.fCloseoperation, // 闭合状态
          keyWord: dataList.keyWord, //  模糊条件
          timeStr: dataList.timeStr, // 趋势---查询的年份
          fProjectposition: dataList.fProjectposition, //任务单--工程部位模糊查询
          taskNo: dataList.taskNo, //任务单---任务单模糊查询
          fStatus: dataList.fStatus, //任务单--完成状态
          page: 1, // 当前页数
          pageSize: 20, // 每页显示条数
          keyType: "2", //张拉 1 压浆 2 必填
          modelType: "2",
        fNote: "0", //新加参数 瑞仓1   其他0

        };
        this.value2 = [this.getList.startDates, this.getList.endDates];
      } else {
        this.getList = {
          fprojectid: "", //任务单
          fCompanyid: data.fCompanyid, // 施工标段id，不为空
          startDates: this.common.getDay(-6) + " " + "00:00:00", // 开始时间
          endDates: this.common.getDay(0) + " " + "23:59:59", // 截至时间
          stationId: "", // 梁场id
          machineId: "", // 压浆机id
          warningLevel: "", // 预警等级
          fCloseoperation: "", // 闭合状态
          keyWord: "", //  模糊条件
          page: 1, // 当前页数
          pageSize: 20, // 每页显示条数
          timeStr: "", // 趋势---查询的年份
          fProjectposition: "", //任务单--工程部位模糊查询
          taskNo: "", //任务单---任务单模糊查询
          fStatus: "", //任务单--完成状态
          keyType: "2", //张拉 1 压浆 2 必填
          modelType: "2",
        fNote: "0", //新加参数 瑞仓1   其他0

        };

        this.value2 = [
          this.common.getDay(-6) + " " + "00:00:00",
          this.common.getDay(0) + " " + "23:59:59",
        ];
      }

      this.mixingPlantList(0, this.getList);
      this.yj_searchForm(this.getList);
    },

    // 获取列表数据
    yj_searchForm(data) {
      this.table_config.thead = [
        {
          label: "月份",
          prop: "type",
          minWidth: "100px",
          align: "center",
        },
      ];
      this.tableData = [];
      this.chartsData = {
        months: [],
        ActualCalculation: [],
        DiskNumber: [],
        rate: [],
        unQuantity: [],
        unrate: [],
      };
      this.listLoading = true;
      if (data.machineId == "所有压浆机") {
        data.machineId = "";
      }
      if (data.stationId == "所有梁场") {
        data.stationId = "";
      }

      window.sessionStorage.setItem(
        "yjSmart-GroutManage_getLists",
        JSON.stringify(data)
      );

      var sc = {
        companyId: data.fCompanyid, // 施工标段id
        timeStr: data.timeStr, // 查询的年份
        machineId: data.machineId, // 拌和机编号
        stationId: data.stationId, // 梁场id
      };
      this.value2 = [data.timeStr + "年1月", data.timeStr + "年12月"];

      getGroutingTrend(sc)
        .then((res) => {
          if (res.errcode == 0) {
            console.log(res);
            var that = this;
            that.listLoading = false;
            // var StrengthGrade = []; //强度
            // var ActualCalculation = []; //方量
            // var DiskNumber = []; // 盘数

            var months = []; //月份
            var assemble = []; //张拉总数
            var quantity = []; //合格数
            var rate = []; //合格率
            var unQuantity = []; //不合格数
            var unrate = []; //不合格率

            var tableData = [{}, {}, {}, {}, {}];
            var data = res.data;
            months = data.dateList; //月份
            assemble = data.totalCountList; //张拉总数
            quantity = data.qualifiedCountList; //合格数
            rate = data.qualifiedRateList; //合格率
            unQuantity = data.unQualifiedCountList; //不合格数
            unrate = data.unQualifiedRateList; //不合格率
            // 图表数据
            this.chartsData = {
              //月份---X轴
              months: months,
              //张拉总数
              ActualCalculation: assemble,
              //合格数
              DiskNumber: quantity,
              //合格率
              rate: rate,
              //不合格数
              unQuantity: unQuantity,
              //不合格率
              unrate: unrate,
            };

            months.map((item, index) => {
              this.table_config.thead.push({
                label: item,
                prop: item,
                minWidth: "100px",
                align: "center",
              });
              tableData[0].type = "压浆总数";
              tableData[0][item] = assemble[index];
              tableData[1].type = "合格数";
              tableData[1][item] = quantity[index];
              tableData[2].type = "合格率(%)";
              tableData[2][item] = rate[index];
              tableData[3].type = "不合格数";
              tableData[3][item] = unQuantity[index];
              tableData[4].type = "不合格率(%)";
              tableData[4][item] = unrate[index];
            });

            that.tableData = tableData;
          } else {
            this.$message.error(res.msg);
            this.listLoading = false;

            return false;
          }
        })
        .catch((error) => {
          console.log(error);
          this.listLoading = false;
        });
    },

    // 获取梁场数据
    mixingPlantList(num, datas) {
      this.bhzDataList = [
        {
          fItemName: "所有梁场",
          fItemValue: "",
        },
      ];
      var data = {
        companyId: datas.fCompanyid, // 施工标段id
        modelType: num, // 类型
        stationType: "4", // 拌合站类型
      };
      getStationmachineList(data)
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;

            arr.map((item) => {
              this.bhzDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    selectBhz(e) {
      this.getList.machineId = "";
      this.getbhjDataMethods(e, "5");
      this.yj_searchForm(this.getList);
    },
    // 获取张拉机设备
    getbhjDataMethods(data, num) {
      this.bhjDataList = [
        {
          fItemName: "所有压浆机",
          fItemValue: "",
        },
      ];
      getMachineListByStationId({ stationId: data, modelType: num })
        .then((res) => {
          if (res.errcode == 0) {
            var arr = res.data.stationmachineList;
            arr.map((item) => {
              this.bhjDataList.push({
                fItemName: item.fMachinename,
                fItemValue: item.fMachineid,
              });
            });
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
    // 时间间隔
    selectTime(e) {
      this.getList.timeStr = e;
      this.yj_searchForm(this.getList);
    },

    getDate() {
      let year = new Date().toString().match(/(\d{4})/)[0];
      this.getList.timeStr = year; // 查询的年份
      this.value2 = [year + "年1月", year + "年12月"];
    },
    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},
  },
};
</script>


<style scoped lang='less'>
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}
.materialCharts {
  height: calc(100% - 200px);
  width: 100%;
}
.mechanism_nav_left .el-date-editor {
  width: 165px !important;
  min-width: 165px !important;
}
</style>


